// Fill out your copyright notice in the Description page of Project Settings.

#include "requestHttpInfo.h"
#include "HttpModule.h"
#include "Interfaces/IHttpRequest.h"
#include "Interfaces/IHttpResponse.h"

const FString FMKSimpleHttpRequestData::Conten_Type = "Content-Type";
const FString FMKSimpleHttpRequestData::User_Agent = "User-Agent";
const FString FMKSimpleHttpRequestData::KeyValueContent = "application/x-www-form-urlencoded;charset=utf-8";
const FString FMKSimpleHttpRequestData::UTF8JsonContent = "application/json;charset=utf-8";
const FString FMKSimpleHttpRequestData::MultipartOrformDataContent = "multipart/form-data";
const FString FMKSimpleHttpRequestData::OctetStreamContent = "application/octet-stream";




FMKSimpleHttpRequestData::FMKSimpleHttpRequestData():
	userLinkObj(nullptr),typ(EMK_SimpleHttpPostTyp::POST), url(""), data("")
{

}

FMKSimpleHttpRequestData::FMKSimpleHttpRequestData(
	EMK_SimpleHttpPostTyp typ_, FString url_, FString ContentType_, FString data_
	, FString keywords/* = TEXT("")*/, UObject* linkObj/* = nullptr*/) :
	userkeywords(keywords), userLinkObj(linkObj),typ(typ_), url(url_),data(data_)
{

}


void FMKSimpleHttpRequestData::SetContenType(FString type)
{
	if (!hardMap.Contains(Conten_Type))
	{
		hardMap.Add(Conten_Type, type);
	}
	else {
		hardMap[Conten_Type] = type;
	}
}


void FMKSimpleHttpRequestData::TryFinishUpHard() 
{
	if (!hardMap.Contains(Conten_Type))
	{
		hardMap.Add(Conten_Type, KeyValueContent);
	}
	if (!hardMap.Contains(User_Agent))
	{
		hardMap.Add(User_Agent,"X-UnrealEngine-Agent");
	}
}


FString FMKSimpleHttpRequestData::GetHttpVerb(EMK_SimpleHttpPostTyp typ)
{
	switch (typ)
	{
	case EMK_SimpleHttpPostTyp::GET:
		return TEXT("GET");
		break;
	case EMK_SimpleHttpPostTyp::POST:
		return TEXT("POST");
		break;
	case EMK_SimpleHttpPostTyp::PUT:
		return TEXT("PUT");
		break;
	case EMK_SimpleHttpPostTyp::Delete:
		return TEXT("delete");
		break;
	default:
		return TEXT("POST");
		break;
	}
	return TEXT("POST");
}



FMSimpleHttpParameter::FMSimpleHttpParameter() 
	:isNumderValue(false)
{

}
FMSimpleHttpParameter::FMSimpleHttpParameter(FString k, FString v, bool isNumder) :
	key(k), value(v), isNumderValue(isNumder){

}

FString FMSimpleHttpParameter::ToParameterKV()const
{
	FString outStr = key.ToLower() + "=" + value;
	return outStr;
}

FString FMSimpleHttpParameter::ToJsonPart()const
{
	FString outStr = "\"" + key + "\":";
	if (!isNumderValue)
	{
		outStr.Append("\"");
	}
	outStr.Append(value);
	if (!isNumderValue)
	{
		outStr.Append("\"");
	}
	return outStr;
}
